package com.zhima.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhima.entity.OjCodeLanguage;
import com.zhima.mapper.OjCodeLanguageMapper;
import com.zhima.service.OjCodeLanguageService;
import com.zhima.vo.CodeLanguageVO;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author zhima
 * @since 2023-09-05
 */
@Service
public class OjCodeLanguageServiceImpl extends ServiceImpl<OjCodeLanguageMapper, OjCodeLanguage> implements OjCodeLanguageService {

    @Override
    public List<CodeLanguageVO> listCodeLanguages() {
        return list().stream().map(c -> BeanUtil.copyProperties(c, CodeLanguageVO.class)).collect(Collectors.toList());
    }

    @Override
    public String queryCodeLanguageNameById(Integer codeLanguageId) {
        return lambdaQuery().eq(OjCodeLanguage::getId, codeLanguageId).one().getName();
    }
}
